package com.we823.cms.model.sys;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.we823.cms.model.BaseModelWithDate;

@Entity
@Table(name="sys_resource")
public class Resource extends BaseModelWithDate<Integer> {

	private static final long serialVersionUID = -1366748198867872072L;
	
	private Integer parentid=0;
	private String name;
	private String identity;
	
	@Enumerated(EnumType.STRING)
	private ResourceType type;
	
	private Integer orderid=0;
	private Integer available=1;
	
	private String linkurl;
	private String style;
	@Transient
	private List<Resource> subresources;
	@Transient
	private boolean hasChild=false;
	
	public Integer getParentid() {
		return parentid;
	}
	public void setParentid(Integer parentid) {
		this.parentid = parentid;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getIdentity() {
		return identity;
	}
	public void setIdentity(String identity) {
		this.identity = identity;
	}
	public ResourceType getType() {
		return type;
	}
	public void setType(ResourceType type) {
		this.type = type;
	}
	public Integer getOrderid() {
		return orderid;
	}
	public void setOrderid(Integer orderid) {
		this.orderid = orderid;
	}
	public Integer getAvailable() {
		return available;
	}
	public void setAvailable(Integer available) {
		this.available = available;
	}
	public List<Resource> getSubresources() {
		return subresources;
	}
	public void setSubresources(List<Resource> subresources) {
		this.subresources = subresources;
	}
	public String getLinkurl() {
		return linkurl;
	}
	public void setLinkurl(String linkurl) {
		this.linkurl = linkurl;
	}
	public String getStyle() {
		return style;
	}
	public void setStyle(String style) {
		this.style = style;
	}
	public boolean getHasChild() {
        hasChild = !(subresources == null || subresources.size() == 0);
		return hasChild;
	}
	public void setHasChild(boolean hasChild) {
		this.hasChild = hasChild;
	}
	public static Resource deepCopy(Resource source) {
		Resource newResourceModel = new Resource();
		newResourceModel.setId(source.getId());
		newResourceModel.setParentid(source.getParentid());
		newResourceModel.setName(source.getName());
		newResourceModel.setIdentity(source.getIdentity());
		newResourceModel.setType(source.getType());
		newResourceModel.setOrderid(source.getOrderid());
		newResourceModel.setAvailable(source.getAvailable());
		newResourceModel.setLinkurl(source.getLinkurl());
		newResourceModel.setStyle(source.getStyle());
		newResourceModel.setSubresources(source.getSubresources());
		return newResourceModel;
	}
	
	
}
